package com.czxy.demo05;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * Created by hp on 2020/2/2.
 */
public class Test24 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
        Properties pro = new Properties();
        FileInputStream fis = new FileInputStream("data.properties");
        pro.load(fis);
        fis.close();
        Class<?> aClass = Class.forName("com.czxy.demo05.User");
        Object o = aClass.newInstance();

        Method setUid = aClass.getDeclaredMethod("setUid", String.class);
        setUid.invoke(o,pro.getProperty("uid"));

        Method setUsername = aClass.getDeclaredMethod("setUsername", String.class);
        setUsername.invoke(o,pro.getProperty("username"));
        Method setPassword = aClass.getDeclaredMethod("setPassword", String.class);
        setPassword.invoke(o,pro.getProperty("password"));
        System.out.println(o);
    }
}
